package br.ufpe.cin.vspeed.gui.render;

import java.awt.Component;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

class CellRendererToolTip extends DefaultTableCellRenderer {
	private static final long serialVersionUID = 8990504250873426394L;

	private final Map<Long, String> tooltip = new HashMap<Long, String>();
	private int row;

	/**
	 * Search the actual line
	 */
	@Override
	public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected,
			final boolean hasFocus, final int row, final int column) {
		final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

		this.row = row;

		return c;
	}

	/**
	 * Return the tool tip based in map
	 */
	@Override
	public String getToolTipText() {
		return this.tooltip.get(new Long(this.row));
	}

	/**
	 * Add the tool tip in the line
	 * 
	 * @param row
	 * @param text
	 */
	public void addToolTip(final int row, final String text) {
		this.tooltip.put(new Long(row), text);
	}
}